from itsdangerous.jws import TimedJSONWebSignatureSerializer as TJWSSerializer
from django.conf import settings
# 1,加密openid
def encode_openid(openid):
    # 创建对象
    serializer = TJWSSerializer(secret_key=settings.SECRET_KEY,expires_in=300)

    # 加密数据
    token = serializer.dumps({'openid':openid})

    # 返回响应
    return token.decode()

def decode_openid(data):
    # 创建加密对象
    serializer = TJWSSerializer(secret_key=settings.SECRET_KEY,expires_in=300)
    # 解密数据
    try:
        dict_data = serializer.loads(data)
    except Exception as e:
        return None
    # 返回响应
    return dict_data.get('openid')





